package com.example.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.myapplication.MainActivity;
import com.example.myapplication.R;
import com.example.myapplication.adapters.FoodAdapter;
import com.example.myapplication.model.Order;

import static com.example.myapplication.activity.ShopActivity.cartFoods;

public class OrderFinishActivity extends AppCompatActivity {

    RecyclerView rc_finish;
    LinearLayout back_main;
    TextView order_number;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_finish);
        rc_finish = findViewById(R.id.rc_finish);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        rc_finish.setLayoutManager(linearLayoutManager);
        rc_finish.setNestedScrollingEnabled(false);
        rc_finish.setAdapter(new FoodAdapter(cartFoods, R.layout.order_confirm_item, getApplicationContext()));

        back_main = findViewById(R.id.back_main);
        order_number = findViewById(R.id.order_number);
        back_main.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(OrderFinishActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });

        String total_amount = getIntent().getStringExtra("total_amount");

        int num1 =(int) (Math.random() * 10);
        int num2 =(int) (Math.random() * 10);
        int num3 =(int) (Math.random() * 10);
        int num4 =(int) (Math.random() * 10);
        int num5 =(int) (Math.random() * 10);
        int num6 =(int) (Math.random() * 10);
        int num7 =(int) (Math.random() * 10);
        int num8 =(int) (Math.random() * 10);
        int num9 =(int) (Math.random() * 10);
        int num10 =(int) (Math.random() * 10);

        String orderNum =  num1+""+num2+""+num3+""+num4+""+num5+""+num6+""+num7+""+num8+""+num9+""+num10+"";
        Order order = new Order(orderNum, Integer.parseInt(total_amount));
        order.save();
    }
}